<template>
  <div class="cartControl">
    <transition name="fade">
        <div class="cart-decrease" v-show="food.count>0 && isShowdes" @click.stop.prevent="decreaseCart($event)">
          <transition name="inner">
          <span class="inner iconfont icon-jian"></span>
          </transition>
        </div>
    </transition>
     <span class="cart-count" v-show="food.qty > 0 && isShowdes ">
      {{food.qty}}
    </span>
    <span class="iconfont icon-jia cart-add" @click.stop.prevent="addCart($event)"></span>
  </div>
</template>

<script type="text/ecmascript-6">
import Vue from "vue";
export default {
  props: {
    food: {
      type: Object
    },
    isShowdes: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    addCart(event) {
      if (!event._constructed) {
        // 去掉自带click事件的点击
        return;
      }
      this.$store.commit("setShow", { target: "remark", status: true });
      // if (!this.food.count) {
      //   Vue.set(this.food, "count", 1);
      // } else {
      //   this.food.count++;
      // }
      this.$store.commit("setGoodInfo", this.food);
      //        event.srcElement.outerHTML
      this.$emit("increment", event.target); // 子组件通过 $emit触发父组件的方法 increment   还
    },
    decreaseCart(event) {
      if (!event._constructed) {
        // 去掉自带click事件的点击
        return;
      }
      if (this.food.count > 0) {
        this.food.qty--;
      }
    }
  }
};
</script>
<style lang="stylus" rel="stylesheet/stylus">
@import 'cartControl.styl';
</style>
